import {defineStore} from "pinia";
import {reactive, ref} from "vue";

export const useGameDataStore = defineStore("game",()=>{
    let panel = reactive([[]]);
    let nowStatus = ref(0);//0为白子，1为黑子
    let winner = ref('');
    let gamers = reactive([]);
    let firstHand = ref(0); //0 先手 1后手
    let gameType = ref(0) // 0人机 1人人 -1未定
    let isGaming = ref(false);

    const changeStatus = (data)=>{
        nowStatus.value = data;
    };
    const changeFirst = (data)=>{
        firstHand.value = data;
    }
    const changeGameType = (data)=>{
        gameType.value = data;
    }
    const changeIsGaming = (data)=>{
        isGaming.value = data;
    }
    const changePanel = (location,status)=>{
        panel[location[1]][location[0]] = status;
    };
    const changeGamers = (data)=>{

    };

    const initialPanel = ()=>{
        if(panel.length!==0){
            panel.splice(0,panel.length);
        }
        for (let i = 0 ; i<15 ; i++){
            let arr = reactive([]);
            for (let j = 0; j<15; j++){
                arr.push(-1);
            }
            panel[i] = arr;
        }
    }

    return {panel,nowStatus,winner,firstHand,gamers,gameType,isGaming
        ,changeStatus,initialPanel,changePanel,changeFirst,changeGameType,changeIsGaming};
})